import { defineStore } from 'pinia'
import { LoginResult } from '@/api/login/model/loginModel'

export const LoginStore = defineStore('loginStore', {
  state: () =>
    ({
      leftMenuList: [],
      permissionList: [],
      sysAdmin: null,
      token: '',
    } as unknown as LoginResult),
  actions: {
    setValue(key: keyof LoginResult, value: any) {
      this[key] = value
    },
    cleanLoginInfo() {
      this.leftMenuList = []
      this.permissionList = []
      this.sysAdmin = null!
      this.token = ''
    },
  },
  persist: {
    enabled: true,
    strategies: [
      {
        key: 'loginStore',
        storage: localStorage,
      },
    ],
  },
})
